/*
自己选择的路 ,跪着也要走完。朋友们 , 虽然这个世界日益浮躁起来,只
要能够为了当时纯粹的梦想和感动坚持努力下去 , 不管其它人怎么样,我
们也能够保持自己的本色走下去。
To the world , you will be a person , but to a person , you
will be the world .                               ——AKPower
*/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
const ll N = 200010;
struct node
{
    ll l, r, maxn;
} a[N << 2];
ll num[N];
void build(ll k, ll l, ll r)
{
    a[k].l = l;
    a[k].r = r;
    if (l == r)
    {
        a[k].maxn = num[l];
        return;
    }
    ll mid = (l + r) >> 1;
    build(k << 1, l, mid);
    build(k << 1 | 1, mid + 1, r);
    a[k].maxn = max(a[k << 1].maxn, a[k << 1 | 1].maxn);
    return;
}

void update(ll k, ll pos, ll x)
{
    if (a[k].l == a[k].r)
    {
        a[k].maxn = x;
        return;
    }
    ll mid = (a[k].l + a[k].r) >> 1;
    if (pos <= mid)
        update(k << 1, pos, x);
    else
        update(k << 1 | 1, pos, x);
    a[k].maxn = max(a[k << 1].maxn, a[k << 1 | 1].maxn);
    return;
}

ll query(ll k, ll l, ll r)
{
    if (a[k].l >= l && a[k].r <= r)
    {
        return a[k].maxn;
    }
    ll mid = (a[k].l + a[k].r) >> 1;
    if (l > mid)
        return query(k << 1 | 1, l, r);
    if (r <= mid)
        return query(k << 1, l, r);
    return max(query(k << 1, l, mid), query(k << 1 | 1, mid + 1, r));
}

int main()
{
    IOS;
    ll n, m;
    while (cin >> n >> m)
    {
        for (ll i = 1; i <= n; i++)
        {
            cin >> num[i];
        }
        build(1, 1, n);
        char flag;
        ll A, B;

        while (m--)
        {
            cin >> flag >> A >> B;
            if (flag == 'Q')
            {
                cout << query(1, A, B) << endl;
            }
            else
                update(1, A, B);
        }
    }

    getchar();
    getchar();
    return 0;
}
